import 'package:sow_app_core/sow_app_core.dart';

class MockNovelRepository extends NovelRepository {
  int subscribeCounter = 0;
  @override
  Future<Novel> novelDetail(String novelId) async => novelId == "-1"
      ? throw NovelNotfoundException()
      : [
          Novel(
              novelId: "1",
              title: "第6975颗繁星",
              author: "游客1656963965397",
              novelTypeList: [
                Classify(
                    classifyId: '1',
                    classifyName: '玄幻',
                    parentId: '1',
                    parentName: '主题')
              ],
              bookStatus: '0',
              visitCount: '9999',
              score: '9.6',
              wordCount: '1321546',
              user: User(5, "15959191701", "游客1656963965397", '666'),
              cover:
                  "https://img9.doubanio.com/view/subject/s/public/s34267705.jpg"),
          Novel(
              novelId: "2",
              title: "傀儡",
              author: "游客1656963965397",
              novelTypeList: [
                Classify(
                    classifyId: '2',
                    classifyName: '悬疑',
                    parentId: '1',
                    parentName: '主题')
              ],
              bookStatus: '1',
              visitCount: '1000',
              score: '6.6',
              wordCount: '666666',
              user: User(5, "15959191701", "游客1656963965397", '666'),
              cover:
                  "https://img9.doubanio.com/view/subject/s/public/s34267705.jpg"),
        ].firstWhere((novel) => novel.novelId == novelId);

  @override
  Future<List<NovelComment>> getBookCommentList(String params) async =>
      [NovelComment('user', 'content', 1)];
  @override
  Future<void> addBookComment(NovelComment params) async => 0;
  @override
  Future<List<Novel>> novelList(String? title) async => <Novel>[
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1"),
        await novelDetail("2"),
        await novelDetail("1")
      ].where((value) => value.title.contains(title ?? '')).toList();
  final subscribes = <Novel>[];
  @override
  Future<void> novelSubscribe(String novelId) async {
    subscribes.add((await novelList(null))
        .firstWhere((value) => value.novelId == novelId));

    ++subscribeCounter;
  }

  @override
  Future<void> novelUnsubscribe(String novelId) async =>
      subscribes.removeWhere((element) => element.novelId == novelId);

  @override
  Future<List<Novel>> getNovelListByClass(String classifyId,
          {String? bookStatus,
          String? wordCountMin,
          String? wordCountMax,
          String? sort}) async =>
      (await novelList(null))
          .where((value) => classifyId.isEmpty
              ? true
              : value.novelTypeList.indexWhere(
                      (element) => element.classifyId == classifyId) !=
                  -1)
          .toList();

  @override
  Future<List<Chapter>> getChapterList(String novelId) async => [
        (await getChapterContent(novelId, "1")),
        (await getChapterContent(novelId, "2"))
      ];

  @override
  Future<Chapter> getChapterContent(String novelId, String catalogue) async => [
        Chapter(
            catalogue: "1",
            chapterId: "1",
            title: "welcome",
            novelId: "1",
            content: "hello world."),
        Chapter(
            chapterId: "1",
            catalogue: "2",
            title: "welcome2",
            novelId: "1",
            content: "hello world2."),
        Chapter(
            chapterId: "1",
            catalogue: "1",
            title: "welcome",
            novelId: "2",
            content: "hello world."),
        Chapter(
            chapterId: "1",
            catalogue: "2",
            title: "welcome2",
            novelId: "2",
            content: "hello world2.")
      ].firstWhere((element) =>
          element.novelId == novelId && element.catalogue == catalogue);

  @override
  Future<void> novelRead(String novelId) async => novelId;

  @override
  Future<List<Novel>> getBookShelf() async => novelList(null);

  @override
  Future<List<Novel>> getReadHistory() async => novelList(null);

  @override
  Future<bool> novelIsSubscribe(String novelId) async =>
      subscribes.where((element) => element.novelId == novelId).isNotEmpty;

  @override
  Future<List<Novel>> getEndBookRank() async => novelList(null);
  @override
  Future<List<Novel>> getHighScoreRank() async => novelList(null);

  @override
  Future<List<Novel>> getHotRank() async => novelList(null);

  @override
  Future<List<Novel>> getRecommendRank() async => novelList(null);

  @override
  Future<List<Classify>> getClassifyList(
          {required workDirection, required novelTagType}) async =>
      [
        Classify(
            classifyName: "玄幻",
            classifyId: '0',
            parentId: '0',
            parentName: '主题'),
        Classify(
            classifyName: "悬疑",
            classifyId: '1',
            parentId: '0',
            parentName: '主题'),
        Classify(
            classifyName: "天才",
            classifyId: '2',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "鬼才",
            classifyId: '3',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "撒旦",
            classifyId: '4',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "书呆子",
            classifyId: '5',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "战神",
            classifyId: '6',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "冬瓜",
            classifyId: '7',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "西瓜",
            classifyId: '8',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "南瓜",
            classifyId: '9',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "吃瓜",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
        Classify(
            classifyName: "吃席",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
        Classify(
            classifyName: "吃土",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
        Classify(
            classifyName: "吃饭",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
      ];
  @override
  Future<List<Classify>> getHotClassifyList({workDirection}) async => [
        Classify(
            classifyName: "玄幻",
            classifyId: '0',
            parentId: '0',
            parentName: '主题'),
        Classify(
            classifyName: "悬疑",
            classifyId: '1',
            parentId: '0',
            parentName: '主题'),
        Classify(
            classifyName: "天才",
            classifyId: '2',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "鬼才",
            classifyId: '3',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "撒旦",
            classifyId: '4',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "书呆子",
            classifyId: '5',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "战神",
            classifyId: '6',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "冬瓜",
            classifyId: '7',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "西瓜",
            classifyId: '8',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "南瓜",
            classifyId: '9',
            parentId: '1',
            parentName: '角色'),
        Classify(
            classifyName: "吃瓜",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
        Classify(
            classifyName: "吃席",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
        Classify(
            classifyName: "吃土",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
        Classify(
            classifyName: "吃饭",
            classifyId: '10',
            parentId: '2',
            parentName: '情节'),
      ];

  @override
  Future<List<Novel>> getGuessYouLikeRank() async => novelList(null);

  @override
  Future<List<Novel>> getHotUpRank() async => novelList(null);

  @override
  Future<List<Novel>> getNewComeRank() async => novelList(null);

  @override
  Future<void> addVisitCount(String params) async => 0;
}
